package com.hadoop.project.component;

import com.hadoop.project.entity.constant.RedisComplexConstant;
import com.hadoop.project.entity.po.TabRank;
import com.hadoop.project.entity.po.UserFlavor;
import com.hadoop.project.entity.po.VideoRank;
import com.hadoop.project.entity.exception.BusinessException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Alexmaodali
 * @usage:redis组件类
 */
@Component("redisComponent")
public class RedisComponent {

    @Resource
    private RedisUtils redisUtils;

    /**
     * TabRankList相关方法
     *
     * @return
     */
    public List<TabRank> getTabRankList() {
        List<TabRank> tabRankList = (List<TabRank>) redisUtils.get(RedisComplexConstant.Key_Tab_Rank_List);
        if (tabRankList == null) throw new BusinessException("tabRankList为空");
        return tabRankList;
    }

    public void setTabRankList(List<TabRank> tabRank) {
        redisUtils.set(RedisComplexConstant.Key_Tab_Rank_List, tabRank);
    }

    /**
     * VideoRankList相关方法
     *
     * @return
     */
    public List<VideoRank> getVideoRankList() {
        List<VideoRank> videoRank = (List<VideoRank>) redisUtils.get(RedisComplexConstant.Key_Video_Rank_List);
        if (videoRank == null) throw new BusinessException("videoRank为空");
        return videoRank;
    }

    public void setVideoRankList(List<VideoRank> videoRank) {
        redisUtils.set(RedisComplexConstant.Key_Video_Rank_List, videoRank);
    }

    /**
     * UserFlavorList相关方法
     *
     * @return
     */
    public List<UserFlavor> getUserFlavorList() {
        List<UserFlavor> userFlavor = (List<UserFlavor>) redisUtils.get(RedisComplexConstant.Key_User_Flavor_List);
        if (userFlavor == null) throw new BusinessException("userFlavor为空");
        return userFlavor;
    }

    public void setUserFlavorList(List<UserFlavor> userFlavor) {
        redisUtils.set(RedisComplexConstant.Key_User_Flavor_List, userFlavor);
    }
}
